#pragma once

#include <QObject>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <queue>
#include "../../entity/SystemLog.h"

class LogService : public QObject {
	Q_OBJECT

public:
	static LogService &getInstance();

	void init(bool enableConsoleOutput = true, const std::string &minLevel = "INFO");

	void log(SystemLog log);

	void stop();  // 清理线程

private:
	LogService();
	~LogService();

	LogService(const LogService &) = delete;
	LogService &operator=(const LogService &) = delete;

	void processLogs();
	bool shouldLog(const std::string &level);

	QThread *workerThread;
	QMutex mutex;
	QWaitCondition cond;
	std::queue<SystemLog> logQueue;
	bool running = false;
	bool consoleOutput = true;
	std::string minLogLevel = "INFO";
};
